# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dm.dm_epidemic_difficult_monitor_details import jms_dm__dm_epidemic_difficult_monitor_details

jms_dm__dm_epidemic_difficult_monitor_summary = SparkSqlOperator(
    task_id='jms_dm__dm_epidemic_difficult_monitor_summary',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_epidemic_difficult_monitor_summary_{{ execution_date | cst_hour }}',
    sql='jms_hi/dm/dm_epidemic_difficult_monitor_summary/execute.sql',
    pool_slots=5,
    executor_cores=2,
    executor_memory='32G',
    driver_memory='4G',
    num_executors=16,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 30,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.autoBroadcastJoinThreshold': 104857600,  # MapJoin 阈值 100M
          'spark.sql.shuffle.partitions': 300,
          },
    hiveconf={
        'hive.exec.dynamic.partition': 'true',  # 动态分区
        'hive.exec.dynamic.partition.mode': 'nonstrict',
        'hive.exec.max.dynamic.partitions': 600,  # 每天生成 20 个分区
        'hive.exec.max.dynamic.partitions.pernode': 40,  # 每天生成 20 个分区
    },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_epidemic_difficult_monitor_summary << [
    jms_dm__dm_epidemic_difficult_monitor_details
]